package com.bytecodezz.app.learnopengl

import android.os.Bundle
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.appcompat.app.AppCompatActivity
import com.bytecodezz.app.learn3.DrawSurfaceView

class Learn3Activity : AppCompatActivity() {
    lateinit var surface_view: DrawSurfaceView
    lateinit var alpha_check_box: CheckBox
    lateinit var alpha_seek_bar: SeekBar


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_learn3)

        surface_view = findViewById(R.id.surface_view)
        alpha_check_box = findViewById(R.id.alpha_check_box)
        alpha_seek_bar = findViewById(R.id.alpha_seek_bar)


        alpha_check_box.setOnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
            surface_view.getNativeRenderer()
                .switchFilterAlpha(surface_view.getDrawRenderer().ptr, isChecked)
        }
        alpha_seek_bar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
                val value = progress.toFloat() / seekBar.max
                surface_view.getNativeRenderer()
                    .setAlphaFilterValue(surface_view.getDrawRenderer().ptr, value)
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {}
            override fun onStopTrackingTouch(seekBar: SeekBar) {}
        })
    }
}